<?php
// +----------------------------------------------------------------------
// | Author: 
// +----------------------------------------------------------------------

namespace app\wechat\controller;
/**
 * 前台首页控制器
 * 主要获取首页聚合数据
 */
class StoreController extends AuthController {
    /**
     * 封面
     */
    public function index(){
        $openid = '';
        if(Session::has('user_info','html5')){
            $openid = Session::get('user_info','html5')['openid'];
        }
        $user_info = db('User')->where(['openid'=>$openid])->find();
        $store_id = $user_info['store_id'];
        $seat_id = input('seat_id');
        $storeInfo = [];
        $seatInfo = [];
        if($store_id !== '' && $store_id > 0){
            $storeInfo = db('Store')->where(['id'=>$store_id])->find();
        }
        if($seat_id !== '' && $seat_id > 0){
            $seatInfo = db('StoreSeat')->where(['id'=>$seat_id])->find();
        }
        
        $this->assign([
            'storeInfo' => $storeInfo,
            'seatInfo' => $seatInfo
        ]);
        return $this->fetch('index');
    }
    /**
     * 封面
     */
    public function hire(){
        $openid = '';
        if(Session::has('user_info','html5')){
            $openid = Session::get('user_info','html5')['openid'];
        }
        $user_info = db('User')->where(['openid'=>$openid])->find();
        $store_id = $user_info['store_id'];
        $seat_id = input('seat_id');
        $storeInfo = [];
        $seatInfo = [];
        if($store_id !== '' && $store_id > 0){
            $storeInfo = db('Store')->where(['id'=>$store_id])->find();
        }
        if($seat_id !== '' && $seat_id > 0){
            $seatInfo = db('StoreSeat')->where(['id'=>$seat_id])->find();
        }
        
        $this->assign([
            'storeInfo' => $storeInfo,
            'seatInfo' => $seatInfo
        ]);
        return $this->fetch('hire');
    }
    /**
     * 封面
     */
    public function returns(){
        $user_info = db('User')->where(['openid'=>$this->open_id])->find();
        $store_id = $user_info['store_id'];
        $seat_id = input('seat_id');
        $storeInfo = [];
        $seatInfo = [];
        if($store_id !== '' && $store_id > 0){
            $storeInfo = db('Store')->where(['id'=>$store_id])->find();
        }
        if($seat_id !== '' && $seat_id > 0){
            $seatInfo = db('StoreSeat')->where(['id'=>$seat_id])->find();
        }
        
        $this->assign([
            'storeInfo' => $storeInfo,
            'seatInfo' => $seatInfo
        ]);
        return $this->fetch('returns');
    }
}